<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备类型">
              <j-dict-select-tag placeholder="请选择设备类型" v-model="queryParam.decixtName" dictCode="zwgl_dpsblist,zdmc,zdmc"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备编号">
              <j-dict-select-tag placeholder="请选择设备编号" v-model="queryParam.devictNo" dictCode="zwgl_dpsblist,sbbh,sbbh"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleWarningTest" type="primary" icon="plus">预警测试</a-button> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-divider type="vertical" v-show="record.eventStatus == '0'" />
          <a @click="handleDealWithData(record.id, 2, '忽略')" v-show="record.eventStatus == '0'">忽略</a>
          <a-divider type="vertical" v-show="record.eventStatus == '0'" />
          <a @click="handleDealWithData(record.id, 1, '处理')" v-show="record.eventStatus == '0'">处理</a>
          <a-divider type="vertical" v-show="record.eventStatus == '0'" />
          <a-dropdown>
            <a @click="handleDetail(record)">详情</a>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <zwgl-event-control-modal ref="modalForm" @ok="modalFormOk"></zwgl-event-control-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ZwglEventControlModal from './modules/ZwglEventControlModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { getAction } from '@/api/manage'
import { postAction } from '@/api/manage'
export default {
  name: 'ZwglEventControlList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ZwglEventControlModal,
  },
  data() {
    return {
      description: '事件监控管理页面',
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key: 'rowIndex',
        //   width: 60,
        //   align: 'center',
        //   customRender: function (t, r, index) {
        //     return parseInt(index) + 1
        //   },
        // },
        {
          title: '设备类型',
          align: 'center',
          dataIndex: 'decixtName',
        },
        {
          title: '设备编号',
          align: 'center',
          dataIndex: 'devictNo',
        },
       
        // {
        //   title: '事件类型',
        //   align: 'center',
        //   dataIndex: 'eventType',
        // },
        {
          title: '事件日期',
          align: 'center',
          dataIndex: 'createTime',
        },
        // {
        //   title: '处理状态',
        //   align: 'center',
        //   dataIndex: 'eventStatus_dictText',
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 250,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: "/mpwlwjc/zwglEventControl/list",
          delete: "/mpwlwjc/zwglEventControl/delete",
          deleteBatch: "/mpwlwjc/zwglEventControl/deleteBatch",
          exportXlsUrl: "/mpwlwjc/zwglEventControl/exportXls",
          importExcelUrl: "mpwlwjc/zwglEventControl/importExcel",
        handleDealWithData: '/mpwlwjc/zwglEventControl/handleDealWithData',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    /**
     * 处理操作
     * @param id
     * @param index
     */
    handleDealWithData(id, index, title) {
      var that = this
      this.$confirm({
        title: '确认' + title,
        content: '是否' + title + '选中数据?',
        onOk: function () {
          that.loading = true
          getAction(that.url.handleDealWithData, { id: id, index: index })
            .then((res) => {
              if (res.success) {
                that.$message.warning('操作成功')
                that.loadData()
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.loading = false
            })
        },
      })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'devictNo', text: '设备编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'decixtName', text: '设备名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'eventType', text: '事件类型', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'createTime', text: '事件日期' })
      fieldList.push({ type: 'string', value: 'eventStatus', text: '处理状态', dictCode: 'event_status' })
      this.superFieldList = fieldList
    },
    /**
     * 预警测试
     */
    handleWarningTest() {
      let that = this
      that.loading = true
      postAction('/sys/message/sysMessageTemplate/sendMsg', {
        msgType: 'system',
        receiver: 'admin',
        templateCode: 'sys_ts_note',
        testData: "{'ts_content':'报警处理功能消息通知'}",
      }).then((res) => {
        if (res.success) {
          that.handlerAddData()
        } else {
          this.$message.error(res.message)
        }
        that.loading = false
      })
    },
    handlerAddData() {
      let that = this
      that.loading = true
      getAction('/modules/zwglEventControl/addNew', {})
        .then((res) => {
          if (res.success) {
            that.$message.success('操作成功')
            that.loadData()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.loading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
